//
//  JHButtonCollectionViewCell.m
//  Liberty Voice
//
//  Created by dlios on 15-5-27.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHButtonCollectionViewCell.h"
#import "UIImageView+WebCache.h"


@interface JHButtonCollectionViewCell()
@property(nonatomic, retain)UILabel *name;
@property(nonatomic, retain)UIImageView *pic;
@end

@implementation JHButtonCollectionViewCell
//#warning 初始化 创 建控件
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //图片
        self.pic = [[UIImageView alloc]init];
        [self.contentView addSubview:_pic];
        [_pic release];
        //文字
        self.name = [[UILabel alloc]init];
        //文本居中
        _name.font = [UIFont systemFontOfSize:self.contentView.frame.size.width / 6];
        self.name.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_name];
        [_name release];
    }
    return self;
}
//#warning 布局信息方法
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    _pic.frame = CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.height - 40);
    _name.frame = CGRectMake(0, _pic.frame.size.height, _pic.frame.size.width, 40);
}
//#warning model对象setter方法,用来给控件赋值
- (void)setButton:(JHButton *)button
{
    if (button != _button) {
        [_button release];
        _button = [button retain];
    }
    [_pic sd_setImageWithURL:[NSURL URLWithString:button.cover_path]];
    _name.text = button.tname;
}
@end
